package cn.xeblog.plugin.tools.read.page;

import cn.hutool.core.thread.ThreadUtil;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * 消息互斥
 */
public class ClickListenerMutex {
    private AtomicBoolean limitShow = new AtomicBoolean(true);

    public void run(Runnable callback) {
        ThreadUtil.execute(() -> {
            if (!limitShow.get()) {
                return;
            }
            limitShow.set(false);
            try {
                if (callback != null) {
                    callback.run();
                }
            } finally {
                limitShow.set(true);
            }
        });
    }
}
